<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html >
<head>
	<meta name="decorator" content="sysDefault" content="text/html; charset=utf-8"/>
	<script type="text/javascript">
	$(document).ready(function() {
		var no = $("#no").val();
		$("#no").focus();
		$("#no").blur(function() {
			if(!$.trim(this.value)){
				$("#tipNo").text("编号不能为空!");
			}else{
				var reg = /^[A-Za-z0-9]+$/;
				if (!reg.test($.trim(this.value))) {
					$("#tipNo").text("编号只能是数字或字母");
					$("#no").focus();
				}else {
					if(!$.trim(this.value)==no){
						$.getJSON("${contextPath}/sys/base/shop/check", 
								{
									"sysBaseShop.no":$.trim(this.value),
									"_":new Date().getTime()
								},
								function(jsonObject) {
									if(!jsonObject.success) {
										$("#tipNo").text("门店编号已经存在");
										$("#no").focus();
									}else {
										$("#tipNo").text("");
									}
						});
					}else{
						$("#tipNo").text("");
					}
				}
				
			}
		});
		$('#name').blur(function() {
			if(!$.trim(this.value)){
				$("#tipName").text("名称不能为空，请输入!");
			}else{
				$("#tipName").text("");
			}
		});
		
		$("#btnSave").click(function(){
			if ( !$('#name').val() ) {
				$("tipName").text("名称不能为空，请输入");
				return;
			}
			$("#shopForm").submit();
		});
	
	});
	</script>
</head>
<body>
	<div class="container-fluid">
		<div class="row">
			<div class="col-xs-12">
				<div class="panel panel-default">
				  <div class="panel-heading">
				    <h3 class="panel-title">修改门店数据
						<a class="btn btn-default btn-sm pull-right" role="button" href="javascript:void(0)" onclick="history.go(-1)">返回</a>
				    </h3>
				  </div>
				  <div class="panel-body">
					<form:form id="shopForm" modelAttribute="sysBaseShop" action="${contextPath}/sys/base/shop/update" method="post" class="form-horizontal" role="form">
						<form:hidden path="id"/>
						<form:hidden path="pid" value="${sysBaseShop.sysBaseShopRegion.id}"/>
						<tags:message content="${message}"/>
							<div class="form-group">
							<label for="no" class="col-sm-2 control-label">门店编号:</label>
							<div class="col-sm-2">
								<form:input id="no" path="no" maxlength="20" class="form-control required"/>
							</div><span id="tipNo" class="requiredSpan col-sm-2 control-label" style="color: red;"></span>
						</div>
						<div class="form-group">
							<label for="name" class="col-sm-2 control-label">门店名称:</label>
							<div class="col-sm-2">
								<form:input id="name" path="name" maxlength="20" class="form-control required"/>
							</div><span id="tipName" class="requiredSpan col-sm-2 control-label" style="color: red;"></span>
						</div>
						<div class="form-group">
							<label for="sysBaseShopRegion" class="col-sm-2 control-label">门店所属区域:</label>
							<label class="col-sm-2 ">${sysBaseShop.sysBaseShopRegion.name }</label>
						</div>
						<div class="form-group">
							<label for="desc" class="col-sm-2 control-label">门店详细信息:</label>
							<div class="col-sm-2">
								<form:textarea id="desc" path="desc" class="form-control"  maxlength="255"/>
							</div>
						</div>
						<div class="form-group">
						  <div class="col-sm-offset-2 col-sm-10">
						    <input id="btnSave" class="btn btn-primary" type="button" value="保 存"/>
							<input class="btn btn-default" type="button" value="返 回" onclick="history.go(-1)"/>
						  </div>
						</div>
					</form:form>
				  </div>
				</div>			
			</div>
		</div>
	</div>
</body>
</html>